
package com.lht.admin.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lht.admin.annotation.SysLog;
import com.lht.admin.utils.R;
import com.lht.admin.controller.AbstractController;
import com.lht.admin.entity.OrderStatisticsEntity;
import com.lht.admin.service.OrderStatisticsService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * 订单统计表Controller
 *
 * @author ZhengZhanWu
 * @date 2020-01-14 23:33:06
 */
@RestController
@RequestMapping("/orderstatistics")
public class OrderStatisticsController extends AbstractController {
    @Autowired
    private OrderStatisticsService orderStatisticsService;

    /**
     * 查看所有列表
     *
     * @param params 查询参数
     * @return R
     */
    @RequestMapping("/queryAll")
    @RequiresPermissions("orderstatistics:list")
    public R queryAll(@RequestParam Map<String, Object> params) {
        List<OrderStatisticsEntity> list = orderStatisticsService.queryAll(params);

        return R.ok().put("list", list);
    }

    /**
     * 分页查询订单统计表
     *
     * @param params 查询参数
     * @return R
     */
    @GetMapping("/list")
    @RequiresPermissions("orderstatistics:list")
    public R list(@RequestParam Map<String, Object> params) {
        Page page = orderStatisticsService.queryPage(params);

        return R.ok().put("page", page);
    }

    /**
     * 根据主键查询详情
     *
     * @param id 主键
     * @return R
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("orderstatistics:info")
    public R info(@PathVariable("id") Long id) {
        OrderStatisticsEntity orderStatistics = orderStatisticsService.getById(id);

        return R.ok().put("orderstatistics", orderStatistics);
    }

    /**
     * 新增订单统计表
     *
     * @param orderStatistics orderStatistics
     * @return R
     */
    @SysLog("新增订单统计表")
    @RequestMapping("/save")
    @RequiresPermissions("orderstatistics:save")
    public R save(@RequestBody OrderStatisticsEntity orderStatistics) {

        orderStatisticsService.add(orderStatistics);

        return R.ok();
    }

    /**
     * 修改订单统计表
     *
     * @param orderStatistics orderStatistics
     * @return R
     */
    @SysLog("修改订单统计表")
    @RequestMapping("/update")
    @RequiresPermissions("orderstatistics:update")
    public R update(@RequestBody OrderStatisticsEntity orderStatistics) {

        orderStatisticsService.update(orderStatistics);

        return R.ok();
    }

    /**
     * 根据主键删除订单统计表
     *
     * @param ids ids
     * @return R
     */
    @SysLog("删除订单统计表")
    @RequestMapping("/delete")
    @RequiresPermissions("orderstatistics:delete")
    public R delete(@RequestBody Long[] ids) {
        orderStatisticsService.deleteBatch(ids);

        return R.ok();
    }
}
